<!DOCTYPE html><!--HTML5 doctype-->
<html>
<head>
<title>Your New Application</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> 
<style type="text/css">
    /* Prevent copy paste for all elements except text fields */
    *  { -webkit-user-select:none; -webkit-tap-highlight-color:rgba(255, 255, 255, 0); }
    input, textarea  { -webkit-user-select:text; }
    
    /* Set up the page with a default background image */
    body {
        background-color:#fff;
        color:#000;
        font-family:Arial;
        font-size:48pt;
        margin:0px;padding:0px;
        background-image:url('images/background.jpg');
    }
</style>
<script type="text/javascript" charset="utf-8" src="http://localhost:58888/_appMobi/appmobi.js"></script> 
<script type="text/javascript" charset="utf-8" src="http://localhost:58888/_appMobi/xhr.js"></script> 
<script type="text/javascript">
/* This function runs once the page is loaded, but appMobi is not yet active */
var init = function(){

};
window.addEventListener("load",init,false);  

/* This code prevents users from dragging the page */
var preventDefaultScroll = function(event) {
    event.preventDefault();
    window.scroll(0,0);
    return false;
};
document.addEventListener('touchmove', preventDefaultScroll, false);

/* This code is used to run as soon as appMobi activates */
var onDeviceReady=function(){
    //Size the display to 768px by 1024px
    AppMobi.display.useViewport(768,1024);
    AppMobi.cache.addToMediaCache("http://youtu.be/bKNJrTlLrug");
	
	//hide splash screen
	AppMobi.device.hideSplashScreen();	
};
document.addEventListener("appMobi.device.ready",onDeviceReady,false);    
</script>

<script type="text/javascript">
/* START ACCELEROMETER SNIPPET   *****************************/

var onDeviceReadyAccel=function(){
       
    //start watching the accelerometer
    watchAccelerometer();
}
  
document.addEventListener("appMobi.device.ready",onDeviceReadyAccel,false);    

/* Accelerometer Code */
var timer;

function successFunction(evt)
{
    //Readings are from -1 to 1 (with 0 being equilibrium in a plane). 
    //Assuning you hold the device in portrait mode with the  screen pointed straight at your chest.
    document.getElementById("accelerometerReadings").innerHTML = "X=" + evt.x + ", Y=" + evt.y + ", Z=" + evt.z;
}

function watchAccelerometer()
{
    var options = {};
    options.frequency = 100; //check every 100 milliseconds
    timer = AppMobi.accelerometer.watchAcceleration(successFunction, options);
}

function clearAccelerometer()
{
    AppMobi.accelerometer.clearWatch(timer);
}

/* END ACCELEROMETER SNIPPET   *****************************/
</script>

<script type="text/javascript">
/* START GEOLOCATION SNIPPET   *****************************/

    var _map = null;
    var _seconds = 30;
    var _llbounds = null;

    var boolTripTrack=true;  //use this flag to continually update the GPS location and leave markers every 30 seconds

    function initialize()
    { }

    function drawMap()
    {
        var latlng = new google.maps.LatLng(currentLatitude,currentLongitude);
        var mapOptions = {
            zoom: 12,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
			zoomControl: true,
            zoomControlOptions: {
              style: google.maps.ZoomControlStyle.SMALL,
			  position: google.maps.ControlPosition.LEFT_TOP
            },
        };

        if (boolTripTrack==true)
        {
            _map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
        }
    }

    //40.7655,-73.97204 = NYC
    var currentLatitude = "40.713768";
    var currentLongitude = "-73.016696";
    var options = {
					 timeout: 10000,
					 maximumAge: 11000,
					 enableHighAccuracy: true
				  };

	var suc = function(p){
		dbAlert("geolocation success",4);

		if( _map == null ) {
			currentLatitude = p.coords.latitude;
			currentLongitude = p.coords.longitude;
			drawMap();
		}

	  	var myLatLng = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
	  	var beachMarker = new google.maps.Marker({
		  position: myLatLng,
		  map: _map
		});

		if( _llbounds == null )
			_llbounds = new google.maps.LatLngBounds(new google.maps.LatLng(p.coords.latitude, p.coords.longitude));
		else
			_llbounds.extend(new google.maps.LatLng(p.coords.latitude, p.coords.longitude));
		_map.fitBounds(_llbounds);
	};

	var fail = function(){
		dbAlert("Geolocation failed. \nPlease enable GPS in Settings.",1);
	};

    var getLocation = function()
    {
        dbAlert("in getLocation",4);
    }
	   
	   
	//AppMobi is ready to roll
    function onDeviceReadyGeoloc()
    {
        try
        {
            if (AppMobi.device.platform.indexOf("Android")!=-1)
            {
                AppMobi.display.useViewport(480,480);
                document.getElementById("map_canvas").style.width="480px";
            }
            else if (AppMobi.device.platform.indexOf("iOS")!=-1)
            {
                if (AppMobi.device.model.indexOf("iPhone")!=-1 || AppMobi.device.model.indexOf("iPod")!=-1)
                {
                    AppMobi.display.useViewport(320,320);
                    document.getElementById("map_canvas").style.width="320px";
                }
                else if (AppMobi.device.model.indexOf("iPad")!=-1)
                {
                    AppMobi.display.useViewport(768,768);
                    document.getElementById("map_canvas").style.width="768px";
                }
            }

			if (AppMobi.geolocation != null)
			{
				AppMobi.geolocation.watchPosition(suc,fail,options);
			}
        }
        catch(e)
        {
			alert(e.message);
        }
    }

    //initial event handler to detect when appMobi is ready to roll
    document.addEventListener("appMobi.device.ready",onDeviceReadyGeoloc,false);
    

/* END GEOLOCATION SNIPPET   *****************************/
</script>

<script>
/* START PUSHMOBI SNIPPET   *****************************/

    /* This snippet of code is a starting point for handling pushMobi Push Messages in 
    an appMobi application. Drop this javascript code into your application's <head>
    HTML tag to allow a user to log in and test basic push text messaging. */
    var didcheckuser = false;

    /* *******************IMPORTANT!!!!!**************************    
    Register for messages as soon as appMobi is loaded (i.e. - in the handler for the appMobi.device.ready event.
    Two ways to do this:
    1) Add the following line to your "OnDeviceReady()" function or the handler you registered for "appMobi.device.ready". 
    registerForMessages();

    OR
    2) If you've already registered the appMobi.device.ready event, the following line
    //registers an additional handler that will also get called. Method (1) is a little cleaner.   
    */
    document.addEventListener("appMobi.device.ready", registerForMessages, false);

    //register this app/user with the push messaging system.
    //This should only happen once per install
    function registerForMessages() {
        //Get the unique identifier of this device
        myUserID = AppMobi.device.uuid; //set a default unique username for the purposes of push
        chosenPassword = "";
        chosenEmail = "";

        //If this device is already registered, just check for new notifications
        if (AppMobi.cache.getCookie("pushmobi_username") == undefined) {
            try {

                //if you want the user to get the same notifications on multiple devices,
                //you must get a username from the user, if not, bypass the following prompts
                chosenUsername = prompt("Choose a username for push messaging", myUserID);
                chosenPassword = prompt("Choose a password for push messaging", "password");
                chosenEmail = prompt("Enter an email address for account confirmation", "");

                AppMobi.notification.addPushUser(chosenUsername, chosenPassword, chosenEmail);
            } catch (e) { alert("error adding push user: " + e.message); }
        }
    }

    /* This callback let's you know whether the app has successfully registered to 
    recieve push notifications. This should only happen once per install (note, though, that if you
    ask the system whether the user/app is registered for push via checkPushUser, or if you attempt
    to reregister the app/user with the system, this even will fire again */
    function notificationsRegistered(event) {
        if (event.success == false) {
            if (didcheckuser == false) {
                AppMobi.notification.checkPushUser(chosenUsername, chosenPassword);
                didcheckuser = true;
            }
            else {
                alert("There was an error adding push notifications " + event.message);
            }
            return;
        }
        else {
            //if the app successfully registered, it's good to save the user information
            //for pulling the right the messages that belong to this user. Then you
            //can prevent unnecessarily trying to re-register the app/user
            AppMobi.cache.setCookie("pushmobi_username", chosenUsername, -1);
            AppMobi.cache.setCookie("pushmobi_password", chosenPassword, -1);
            AppMobi.cache.setCookie("pushmobi_email", chosenEmail, -1);
        }

        updateNotifications();
    }

    var clearList = [];

    /* Callback for handling notifications */
    function updateNotifications(event) {
        try {
            var myNotifications = AppMobi.notification.getNotificationList();
            var len = myNotifications.length;

            for (i = 0; i < len; i++) {
                //get the pushMobi message data
                msgObj = AppMobi.notification.getNotificationData(myNotifications[i]);

                //display the pushMobi message as a notification if there is no data
                if (msgObj.isRich == false) { //Is this a simple text push message?

                    //YOUR CODE HERE - possibly do somethign more interesting than alert the text
                        alert(msgObj.msg);
                    //////

                    //remove the message from the server otherwise the app will 
                    //think it has more messages waiting for it
                    AppMobi.notification.deletePushNotifications(msgObj.id);
                }
                else { //Sweet - Rich Push Message, show it in the rich viewer
                    AppMobi.notification.showRichPushViewer(msgObj.id, 10, 10, 10, 10, 80, 80);
                    break; // only one rich message at a time, will resume after richViewerClosed
                }
            }
        }
        catch (e) { alert("error in updateNotifications: " + e.message); }
    }

    //event that let's you know that the user's app is enabled to receive push
    document.addEventListener("appMobi.notification.push.enable", notificationsRegistered, false);
    //register to be notified when a push message is received by the app
    document.addEventListener('appMobi.notification.push.receive', updateNotifications, false);
    //Two rich push msgs, can't be viewed at the same time
    //register to be notified when a rich push message is closed (so that you can launch the next one)
    document.addEventListener("appMobi.notification.push.rich.close", richViewerClosed, false);
    //optional: if you'd like to know when the rich push msg viewer is busy, register a handler
    //document.addEventListener("appMobi.notification.push.rich.busy", [mybusyhandler], false);

    function richViewerClosed(event) {
        //remove the message from the server
        AppMobi.notification.deletePushNotifications(event.id);

        // resume viewing push messages
        updateNotifications();
    }

/* END PUSHMOBI SNIPPET   *****************************/
</script>



<script>
/* START STATMOBI SNIPPET   *****************************/


/* This sample function records an event ID, as well as an optional
set of name/value pairs as a query string to the statMobi Analytics
logs.*/

/* Drop this javascript function into the <head> element of your
application's index.html page and call it everywhere you want to
record an analytics event. It takes two parameters. The first is an
event identifier string and the second is an optional key/value query
string parameter. */

function addAnalyticsDataPoint(eventID,queryString)
{
   try
   {
       if (queryString==null) { queryString = ""; }
       AppMobi.analytics.logPageEvent("/application/" + eventID +
".event", queryString, "", "", 0, "index.html");
   }
   catch(e) {}
}

/* END STATMOBI SNIPPET   *****************************/
</script>

<script type="text/javascript" >
/* START LIVE UPDATE SNIPPET   *****************************/

/* If you decide to allow your application to handle Live Updates itself, 
this snippet will give you a starting point. Drop this javascript code 
into your application's <body> HTML tag to detect if an update has been 
successfully downloaded. */

/* This event handler captures the event thrown when an update becomes available while an application is running */
document.addEventListener("appMobi.device.update.available",onUpdateAvailable,false); 
function onUpdateAvailable(evt) {
  /* test to see if the event is appMobi.device.update.available */
  if (evt.type == "appMobi.device.update.available") {
    /* there is an update available *while* the application is running - decide what to do */
    if (confirm(evt.updateMessage)==true) {
      updateApplication();
    }
    else {
      updateApplicationLater();
    }
  }
}

document.addEventListener("appMobi.device.ready",onDeviceReadyTestForUpdate,false);
function onDeviceReadyTestForUpdate(evt)
{
  /* appMobi.updateAvailable indicates whether or not an over the air update is available or not. */
  if (AppMobi.updateAvailable==true)
  {
    //there is an application update available at startup
    if (confirm(AppMobi.updateMessage)==true) {
      updateApplication();
    }
    else {
      updateApplicationLater();
    }
  }
}

function updateApplication() {
    /* installs an update if one is available */
    AppMobi.device.installUpdate();
}
    
function updateApplicationLater() {
    /* add any code to indicate that the update has been postponed */
    alert("The update has been postponed");
}
document.addEventListener("appMobi.camera.picture.add",onSuccess); 
document.addEventListener("appMobi.camera.picture.busy",onSuccess); 
document.addEventListener("appMobi.camera.picture.cancel",onSuccess); 


function capturePhoto() {
  AppMobi.camera.importPicture();
}

function onSuccess(evt) {

  if (evt.success == true)
  {
    // create image 
    var image = document.createElement('img');
    image.src=AppMobi.camera.getPictureURL(evt.filename);
    image.id=evt.filename;
    document.body.appendChild(image);
  }
  else
  {
    if (evt.message != undefined)
    {
        alert(evt.message);
    }
    else
    {
        alert("error capturing picture");
    }
  }
}


/* END LIVE UPDATE SNIPPET   *****************************/
</script>

</head>
<body>
<a href="javascript:openwindow()">Go to Asessment Template</a>
<script>
drawMap();

function openwindow()
{
window.open('assessmentTemplate.html', 'newwindow', 'scrollbars=yes');
}

</script>


</script>
<!-- content goes here-->
</body>
</html>
